package svc

import (
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"message/internal/config"
	"message/models"
)

type ServiceContext struct {
	Config                  config.Config
	Conn                    sqlx.SqlConn
	MessageModel            models.MessageModel
	MessageStatusModel      models.MessageStatusModel
	MessageAggregationModel models.MessageAggregationModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn(c.DataBase.Driver, c.DataBase.DSN)
	messageModel := models.NewMessageModel(conn, c.Cache)
	messageStatusModel := models.NewMessageStatusModel(conn, c.Cache)
	return &ServiceContext{
		Config:                  c,
		Conn:                    conn,
		MessageModel:            messageModel,
		MessageStatusModel:      messageStatusModel,
		MessageAggregationModel: models.NewMessageAggregationModel(conn),
	}
}
